﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities.System;
using DataAccess.SQL;
using System.Data;

namespace BLL.Common
{
    public class CheckBoxBO
    {

        public List<CheckBox_List> GetAllCheckItems()
        {

            string sql = @"SELECT t.FAC_KEY ,t.CHECKBOX_TYPE_CODE,l.checkboxlist_code,l.checkboxlist_name,l.sequence,l.SYS_CHECKBOXLIST_KEY
                            ,l.default_value FROM sbrm_sys_checkbox_type t 
                            JOIN sbrm_sys_checkboxlist l ON t.checkbox_type_key=l.checkbox_type_key
                            where t.active='Y' AND L.ACTIVE='Y' order by l.checkbox_type_key,l.sequence";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;

        }
        /// <summary>
        /// 获取某厂项目阶段资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetProjectStage(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='ProjectStage' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
        /// <summary>
        /// 获取某厂样品类别资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetCategory(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='Category' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
        /// <summary>
        /// 获取某厂功能测试冶具状态资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetFuncTestMacStatus(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='FuncTestMacStatus' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
        /// <summary>
        /// 获取某厂样品处置资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetSampleManage(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='SampleManage' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
        /// <summary>
        /// 获取某厂报告类型资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetReportType(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='ReportType' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
        /// <summary>
        /// 根据CHECKLISTKEY获取CHECKLIST信息
        /// </summary>
        /// <param name="checklistkey">CHECKLISTKEY</param>
        /// <returns></returns>
        public CheckBox_List GetCheckListByKey(string checklistkey)
        {
            string sql = string.Format("Select * From sbrm_sys_checkboxlist Where SYS_CHECKBOXLIST_KEY={0}", checklistkey);
            CheckBox_List result = SqlHelper.ExecuteEntity<CheckBox_List>(sql, CommandType.Text);
            return result;
        }
        /// <summary>
        /// 获取某厂排程类别资讯
        /// </summary>
        /// <param name="facKey"></param>
        /// <returns></returns>
        public List<CheckBox_List> GetScheduleType(string facKey)
        {
            string sql = "select SYS_CHECKBOXLIST_KEY,"
            + " CHECKBOXLIST_NAME,"
            + " SEQUENCE"
            + " from SBRM_SYS_CHECKBOXLIST"
            + " where CHECKBOX_TYPE_KEY= (SELECT  CHECKBOX_TYPE_KEY"
            + " FROM SBRM_SYS_CHECKBOX_TYPE  WHERE  CHECKBOX_TYPE_CODE ='ScheduleType' AND  FAC_KEY =" + facKey + ")"
            + " AND  FAC_KEY =" + facKey + " AND  ACTIVE='Y'"
            + " order by SEQUENCE";
            List<CheckBox_List> lst = SqlHelper.ExecuteList<CheckBox_List>(sql, CommandType.Text);
            return lst;
        }
    }
}
